HDU 2594 Simpsons ' Hidden Talents (The Simpsons potential talent)Time limit:2000/1000 MS (java/others)Memory limit:32768/32768 K (java/others)
"Description"
"Title description"
Homer:marge, I just figured out a-to discover some of the talents we weren ' t aware we had.Marge:yeah, what's it?Homer:take me for example. I want to find out if I had a talent in politics, OK?Marge:
Simpsons ' Hidden Talents
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)Total submission (s): 4543 Accepted Submission (s): 1648
problem DescriptionHomer:marge, I just figured out a-to discover some of the talents we weren ' t aware we had.
Marge:yeah, what's it?
Homer:take me for example. I want to find out if I had a talent in politics, OK?
Marge:ok.
Homer:so I Take some politician's name, say Clinton, and
Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2594Analysis: To determine whether there are substrings in two strings, can be used as s1 prefix s2 suffix. Consider merging the two strings and then directly using the next array. The condition that may occur after merging is that the substring is greater than S1 | | The length of the S2, so you have to make a judgment./*Simpsons ' Hidden talentstime limit:2000/1000 MS (java/others) Memory limit:
Simpsons ' Hidden TalentsTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)Total submission (s): 4683 Accepted Submission (s): 1702Problem Descriptionhomer:marge, I just figured out a-to discover some of the talents we weren ' t aware we had.Marge:yeah, what's it?Homer:take me for example. I want to find out if I had a talent in politics, OK?Marge:ok.Homer:so I Take some politician's name, say Clinton, and try to find the l
single line that contains the longest string that is a prefix of S1 and a suffix of S2, followed by the length of that prefix. if the longest such string is the empty string, then the output shocould be 0.
The lengths of S1 and S2 will be at most 50000.
Sample Input
clintonhomerriemannmarjorie
Sample output
0rie 3 Question: Find the longest Public String Of the prefix of the first string and the suffix of the second string. The idea is to connect the two strings, use the next [] array of KMP to
Simpsons 'den den talentstime limit: 1000 msmemory limit: 32768 kbthis problem will be judged on HDU. Original ID: 2594
64-bit integer Io format: % i64d Java class name: Main HOMER: Marge, I just figured out a way to discover some of the talents we weren't aware we had.
MARGE: Yeah, what is it?
HOMER: Take me for example. I want to find out if I have a talent in politics, OK?
MARGE: OK.
HOMER: So I take some politician's name, say Clinton, and try to
){ while(cin>>sa>>SB) { intk=solve (); if(k) { for(intI=0; i) printf ("%c", Sa[i]); printf ("%d\n", K); } Elseprintf ("0\n"); } return 0;}KMP: See the prefix and suffix of the match must be KMP Ah, put SB in the back of the SA to find an next array can be = =However, when Next[sa.length () -1]>min (Sa.length (), Sb.length ()) (the first SA is the stitched string, the latter two are the original string).Do not short-fall back to the appropriate location.See the code for detai
Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2594Idea: Concatenate two to find the next array is the sum of the two, the length of the traverse should be less than the minimum value of two strings1#include 2#include 3#include 4#include 5#include string.h>6#include 7#include 8#include 9#include Ten#include Set> One #defineDinf 0x3f3f3f3f AtypedefLong Longll; - //const int max= (1 - using namespacestd; the - Const intmax=50000+Ten; - Chars1[max*2],s2[max]; - intnext[max*2]; + - v
consists of the lines. The first line contains S1 and the second line contains S2. Assume all letters is in lowercase.Outputoutput consists of a single line that contains the longest string which is a prefix of S1 and a suffix of S2, followe D by the length of the. prefix. If the longest such string is the empty string and then the output should be 0.The lengths of S1 and S2 would be in most 50000.Sample InputclintonhomerriemannmarjorieSample Output0rie 3#include #includestring.h>#include#inclu
Simpsons 'den den Talents
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)Total submission (s): 1658 accepted submission (s): 605Problem descriptionhomer: Marge, I just figured out a way to discover some of the talents we weren't aware we had.MARGE: Yeah, what is it?HOMER: Take me for example. I want to find out if I have a talent in politics, OK?MARGE: OK.HOMER: So I take some politician's name, say Clinton, and try to
S2. Assume all letters is in lowercase.OutputOutput consists of a single line this contains the longest string is a prefix of S1 and a suffix of S2, followed By the length of this prefix. If the longest such string is the empty string and then the output should be 0.The lengths of S1 and S2 'll be in most 50000.Sample InputClintonhomerriemannmarjorieSample Output0rie 3SourceHDU 2010-05 Programming ContestrecommendLCYChange a a , a string, in the original B-string matches the original a string p
Topic Links:http://acm.hdu.edu.cn/showproblem.php?pid=2594Main topic:Give you two strings of S1 and S2, which is the longest string and length of both the S1 prefix and the S2 suffix.Ideas:KMP algorithm next[j] = = k is the essence of the current letter mismatch, the pattern string of the first K (s0~sk-1) and position J beforeK-item (SJ-1-K~SJ-1) is equal, this K-value is all that satisfies the above situation maximum. So the meaning of Next[len]is the longest prefix of the pattern string and t
Simpsons 'den den Talents
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)Total submission (s): 2875 accepted submission (s): 1095Problem descriptionhomer: Marge, I just figured out a way to discover some of the talents we weren't aware we had.
MARGE: Yeah, what is it?
HOMER: Take me for example. I want to find out if I have a talent in politics, OK?
MARGE: OK.
HOMER: So I take some politician's name, say Clinton, and t
Here are two strings. the prefix of your first string is equal to the maximum length of the suffix of the second string.
Solution: KMP: match twice, but the method is clever. Just find next separately.
Solution code:
1 // file name: getnext. CPP 2 // Author: darkdream 3 // created time: tuesday, September 09, 2014, 02 seconds, 4 5 # include View code
HDU 2594 Simpsons 'den den talents KMP
Link:
http://acm.hdu.edu.cn/showproblem.php?pid=2594
The main effect of the topic:
Give two strings S1 and S2, and find the longest string that is the prefix of the S1 and is the S2 suffix.
Analysis and Summary:
Really understand good KMP
Question link:
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2594
Question meaning:
For two strings, find that the prefix of the first string is the maximum length of the suffix of the second string.
Solution:
First obtain the next array of the
The question is to find the prefix of the first character and the Public sequence with the largest Suffix of the last string, and output it...
Combine the two strings and find the next array in KMP. However, be sure not to exceed the length of a
KMP: Find a string that is both the prefix of the S1 string and the suffix of S2, and requires the maximum length of this string. The idea is to regard the S2 string as a text string, the S1 string as a mode string, and the two strings as KMP. For
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.